﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Dashboard.Models;

namespace Dashboard.Controllers
{
    public class LogsController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.listOfCustomLogs = LogsManager.Instance.GetLogs();
            ViewBag.listOfWinLogs = LogsManager.Instance.GetEventLogs();

            return View();
        }

        public ActionResult DownloadLogWithName(string id)
        {
            FilePathInfo info = LogsManager.Instance.GetPathLog(id);

            return File(info.FileName, info.ContentType, info.FileDownloadName);
        }

        public ActionResult DownloadWindowsLog(string id)
        {
            FilePathInfo info = LogsManager.Instance.GetEventLog(id);
            if (String.IsNullOrEmpty(info.FileDownloadName))
            {
                return View();
            }

            return File(info.FileName, info.ContentType, info.FileDownloadName);
        }

        public ActionResult DownloadLogsDirectory(string id)
        {
            FilePathInfo info = LogsManager.Instance.CreateZipFolder(id);
            if (String.IsNullOrEmpty(info.FileDownloadName))
            {
                return View();
            }

            return File(info.FileName, info.ContentType, info.FileDownloadName);
        }
    }
}
